package br.gov.ibama.client.componentes;

import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
import com.smartgwt.client.widgets.form.fields.events.FocusEvent;
import com.smartgwt.client.widgets.form.fields.events.FocusHandler;
import com.smartgwt.client.widgets.form.fields.events.KeyDownEvent;
import com.smartgwt.client.widgets.form.fields.events.KeyDownHandler;
import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent;
import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler;
import com.smartgwt.client.widgets.form.fields.events.KeyUpEvent;
import com.smartgwt.client.widgets.form.fields.events.KeyUpHandler;

public class ComboGenericaDSObrigatorio extends ComboGenericaDS {

	public ComboGenericaDSObrigatorio(String name, String title,
			String datasource, String campoChave, String campoShow) {
		super(name, title, datasource, campoChave, campoShow);
		configuraCombobox();
		setaComportamentos();
		this.redraw();
	}

	private void configuraCombobox() {
		this.setRequired(true);
		this.setRequiredMessage(BasisConstantes.MSG_OBRIGATORIO);
		this.setPrompt(BasisConstantes.MSG_OBRIGATORIO);
		this.setTextBoxStyle("_obrigatorio");
	}

	private void setaComportamentos() {
		this.addBlurHandler(new BlurHandler() {

			public void onBlur(BlurEvent event) {
				if (event.getItem().getValue() == null) {
					new FolhaEstiloComponentes().setaPadraoCORObrigatorio();
				} else {
					new FolhaEstiloComponentes().setaPadraoCORPreenchido();
				}
			}
		});
		this.addFocusHandler(new FocusHandler() {

			public void onFocus(FocusEvent event) {
				if (event.getItem().getValue() == null) {
					new FolhaEstiloComponentes().setaPadraoCORObrigatorio();
				} else {
					new FolhaEstiloComponentes().setaPadraoCORPreenchido();
				}
			}
		});
		this.addKeyDownHandler(new KeyDownHandler() {

			public void onKeyDown(KeyDownEvent event) {
				if (event.getItem().getValue() == null) {
					new FolhaEstiloComponentes().setaPadraoCORObrigatorio();
				} else {
					new FolhaEstiloComponentes().setaPadraoCORPreenchido();
				}
			}
		});
		this.addKeyPressHandler(new KeyPressHandler() {

			public void onKeyPress(KeyPressEvent event) {
				if (event.getItem().getValue() == null) {
					new FolhaEstiloComponentes().setaPadraoCORObrigatorio();
				} else {
					new FolhaEstiloComponentes().setaPadraoCORPreenchido();
				}
			}
		});
		this.addKeyUpHandler(new KeyUpHandler() {

			public void onKeyUp(KeyUpEvent event) {
				if (event.getItem().getValue() == null) {
					new FolhaEstiloComponentes().setaPadraoCORObrigatorio();
				} else {
					new FolhaEstiloComponentes().setaPadraoCORPreenchido();
				}
			}
		});
	}
}
